package com.webbei.shoppingCar.action;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.struts2.ServletActionContext;

import com.webbei.myCustom.action.MyUtil;
import com.webbei.pojo.Customs;
import com.webbei.shoppingCar.service.shoppingCarService;

public class showShopCar {

	private shoppingCarService scs;

	private List<Customs> cuslist;
	private Integer listsize;
	private Double totalprice;
	private Long tid;
	private String tradename;
	private String remark;
	public String execute(){
		Map session=ServletActionContext.getContext().getSession();
		String username=(String) session.get("username");
		cuslist=(List<Customs>)session.get("shopcar");
		if(cuslist==null) return "error";
		listsize=new Integer(0);
		totalprice=new Double(0.0);
		tid=new Long(0);
		tradename=new String("");
		listsize=cuslist.size();
		if(listsize==1){
			tid=cuslist.get(0).getCustomId();
		}else{
			tid=MyUtil.getId();
		}
		for(int c=0;c<cuslist.size();c++){
			totalprice+=cuslist.get(c).getCustomPrice();
			if(c!=0) tradename+=",";
			tradename+=cuslist.get(c).getCustomName();
		}
		Set<String> markSet=new HashSet<String>();
		for(Customs cc:cuslist){
			if(cc.getCustomContent()!=null&&!markSet.contains(cc.getCustomContent())){
				markSet.add(cc.getCustomContent());
			}
		}
		remark="";
		if(markSet.size()>0){
			for(String ss:markSet){
				remark+=(ss+",");
			}
			remark=remark.substring(0,remark.length()-1);
		}
		return "success";
	}

	public void setScs(shoppingCarService scs) {
		this.scs = scs;
	}

	public List<Customs> getCuslist() {
		return cuslist;
	}

	public void setCuslist(List<Customs> cuslist) {
		this.cuslist = cuslist;
	}

	public Integer getListsize() {
		return listsize;
	}

	public void setListsize(Integer listsize) {
		this.listsize = listsize;
	}

	public Double getTotalprice() {
		return totalprice;
	}

	public void setTotalprice(Double totalprice) {
		this.totalprice = totalprice;
	}

	public Long getTid() {
		return tid;
	}

	public void setTid(Long tid) {
		this.tid = tid;
	}

	public String getTradename() {
		return tradename;
	}

	public void setTradename(String tradename) {
		this.tradename = tradename;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

}
